package com.yunji.web.base;

import com.yunji.base.business.MultiRoleBusiness;
import com.yunji.common.annotation.Log;
import com.yunji.common.base.BaseController;
import com.yunji.common.base.response.Response;
import com.yunji.common.base.response.ResponseHelper;
import com.yunji.common.enums.common.BusinessType;
import com.yunji.common.model.domain.SysRoleDO;
import com.yunji.common.utils.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @version 1.0
 * @Project: yunji-coffee
 * @Package com.yunji.web.user
 * @FileName MultiRoleController.java
 * @Copyright Copyright © 2024 云集互联. All Rights Reserved
 * Company		com
 * @CreateTime 2024-08-20 14:09:12
 * @Description 多角色处理
 * @Modification Author                    History Time			Version				Description
 * --------------------------------------------------------------------------------
 * HuaAo0803@163.com	2024-08-20 14:09:12		1.0					1.0 Version
 * @since JDK 1.8.0_202
 */
@RestController
@Api(tags = "管理端-多角色管理")
@RequestMapping("/container/role")
public class MultiRoleController extends BaseController {
    @Resource
    MultiRoleBusiness business;

    @GetMapping("/list")
    @ApiOperation("查询角色信息列表")
    public Response<List<SysRoleDO>> list(SysRoleDO role) {
        List<SysRoleDO> list = business.search(role);
        return ResponseHelper.successWithPage(list);
    }

    @PostMapping("/export")
    @ApiOperation("导出角色信息列表")
    @Log(title = "角色信息", businessType = BusinessType.EXPORT)
    public void export(SysRoleDO role) {
        List<SysRoleDO> list = business.search(role);
        ExcelUtil<SysRoleDO> util = new ExcelUtil<>(SysRoleDO.class);
        util.exportExcel(response, list, "角色信息数据");
    }

    @GetMapping(value = "/{id}")
    @ApiOperation("获取角色信息详细")
    public Response<SysRoleDO> select(@PathVariable("id") Long id) {
        return ResponseHelper.success(business.select(id));
    }

    @PostMapping
    @ApiOperation("创建角色信息")
    @Log(title = "角色信息", businessType = BusinessType.INSERT)
    public Response<Long> create(@RequestBody SysRoleDO role) {
        return ResponseHelper.success(business.create(role));
    }

    @PutMapping
    @ApiOperation("修改角色信息")
    @Log(title = "角色信息", businessType = BusinessType.UPDATE)
    public Response<String> update(@RequestBody SysRoleDO role) {
        business.update(role);
        return ResponseHelper.success("编辑成功");
    }

    @DeleteMapping("/{ids}")
    @ApiOperation("删除角色信息")
    @Log(title = "角色信息", businessType = BusinessType.DELETE)
    public Response<String> remove(@PathVariable Long... ids) {
        business.delete(ids);
        return ResponseHelper.success("删除成功");
    }
}